[HLW8012] Improve stability and resolution Voltage/Current measurement #4328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Every now and then there would be some fluke measurements, due to some late interrupt handling. Now the pulses on CF1 are counted as well as measured. For low pulse counts, only the duration of the last pulse is taken as it may take some time to get stable pulses. Thus then it is better to use only the last one of a period. For high pulse counts, it is better to take the duration over a longer time and then average over the nr of pulses.
Before this, the "resolution" of the mains voltage measurements were roughly 8V and thus completely unusable.
The resolution of the POW r1 using the code from before this PR.
And with this PR included:
With these changes, the resolution of the mains voltage is closely following the measured voltage of the CSE7766, used in the Sonoff POW2. (less than 0.1 V off in the same wall socket)
Left Sonoff POW r1, right Sonoff POW r2
Both measuring interval of 60 seconds, but not exactly at the same second.